'use strict';

/**
 * @ngdoc directive
 * @name izzyposWebApp.directive:adminPosHeader
 * @description
 * # adminPosHeader
 */

angular.module('sbAdminApp')
  .directive('sidebar', ['$location', '$rootScope', 'CourseService',
    function() {
      return {
        templateUrl: 'scripts/directives/sidebar/sidebar.html',
        restrict: 'E',
        replace: true,
        scope: {},
        controller: function($scope, $rootScope, CourseService) {
          $scope.selectedMenu = 'dashboard';
          $scope.collapseVar = 0;
          $scope.multiCollapseVar = 0;

          $scope.$watch(function() {
            return $rootScope.courselist;
          }, function() {
            $scope.courselist = $rootScope.courselist;
          }, true);

          CourseService.query({},
            function(courselist) {
              console.log(courselist);
              $rootScope.courselist = courselist;
            });
          $scope.check = function(x) {

            if (x == $scope.collapseVar)
              $scope.collapseVar = 0;
            else
              $scope.collapseVar = x;
          };

          $scope.multiCheck = function(y) {

            if (y == $scope.multiCollapseVar)
              $scope.multiCollapseVar = 0;
            else
              $scope.multiCollapseVar = y;
          };
        }
      }
    }
  ]);